package stdio.costa.moca.model;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.ManyToOne;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

import stdio.costa.UuidPersistentable;
import stdio.costa.moca.pdf.PdfGeneratable;

@Entity
@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
public class Postcard extends UuidPersistentable implements PdfGeneratable {

	private static final long serialVersionUID = 7676767784269494633L;

	@ManyToOne
	private Img photo;

	@ManyToOne
	private Img wish;

	@ManyToOne
	private Img stamp;

	@ManyToOne(cascade = { CascadeType.PERSIST })
	private Address address = new Address();

	@ManyToOne
	private User sender;

	private boolean pdfGenerated;

	private boolean cardCreated;

	@XmlTransient
	private byte[] pdf;

	@Override
	public boolean isReadyForPdfGeneration() {
		return photo.isReadyForPdfGeneration() && wish.isReadyForPdfGeneration() && stamp.isReadyForPdfGeneration()
				&& address.isReadyForPdfGeneration();
	}

	public Img getPhoto() {
		return photo;
	}

	public void setPhoto(Img photo) {
		this.photo = photo;
	}

	public Img getWish() {
		return wish;
	}

	public void setWish(Img wish) {
		this.wish = wish;
	}

	public Img getStamp() {
		return stamp;
	}

	public void setStamp(Img stamp) {
		this.stamp = stamp;
	}

	public Address getAddress() {
		return address;
	}

	public void setAddress(Address address) {
		this.address = address;
	}

	public User getSender() {
		return sender;
	}

	public void setSender(User sender) {
		this.sender = sender;
	}

	public boolean isPdfGenerated() {
		return pdfGenerated;
	}

	public void setPdfGenerated(boolean pdfGenerated) {
		this.pdfGenerated = pdfGenerated;
	}

	public boolean isCardCreated() {
		return cardCreated;
	}

	public void setCardCreated(boolean cardCreated) {
		this.cardCreated = cardCreated;
	}

	public byte[] getPdf() {
		return pdf;
	}

	public void setPdf(byte[] pdf) {
		this.pdf = pdf;
	}
}
